1
|
|
|
/* |
2
|
|
|
* CMS Pico - Integration of Pico within your files to create websites. |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2017 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** global: OC */ |
27
|
|
|
/** global: pico_elements */ |
28
|
|
|
/** global: pico_result */ |
29
|
|
|
/** global: pico_define */ |
30
|
|
|
|
31
|
|
|
var pico_nav = { |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
retrieveWebsites: function () { |
35
|
|
|
$.ajax({ |
36
|
|
|
method: 'GET', |
37
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/websites'), |
38
|
|
|
data: {} |
39
|
|
|
}).done(function (res) { |
40
|
|
|
pico_result.displayWebsites(res.websites); |
41
|
|
|
}); |
42
|
|
|
}, |
43
|
|
|
|
44
|
|
|
updateNewWebsite: function (url) { |
45
|
|
|
pico_elements.cms_pico_new_url.text(pico_define.nchost + pico_define.sites + url); |
46
|
|
|
pico_nav.refreshNewFolder(); |
47
|
|
|
}, |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
pickFolderResult: function (folder) { |
51
|
|
|
pico_elements.cms_pico_new_folder_result = folder; |
52
|
|
|
pico_nav.refreshNewFolder(); |
53
|
|
|
}, |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
refreshNewFolder: function () { |
57
|
|
|
pico_elements.cms_pico_new_folder.val(pico_elements.cms_pico_new_folder_result + '/' + |
58
|
|
|
pico_elements.cms_pico_new_website.val()); |
59
|
|
|
}, |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
createNewWebsite: function () { |
63
|
|
|
|
64
|
|
|
pico_nav.creatingWebsite(true); |
65
|
|
|
var data = { |
66
|
|
|
name: pico_elements.cms_pico_new_name.val(), |
67
|
|
|
website: pico_elements.cms_pico_new_website.val(), |
68
|
|
|
path: pico_elements.cms_pico_new_folder.val(), |
69
|
|
|
template: pico_elements.cms_pico_new_template.val() |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
$.ajax({ |
73
|
|
|
method: 'PUT', |
74
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website'), |
75
|
|
|
data: { |
76
|
|
|
data: data |
77
|
|
|
} |
78
|
|
|
}).done(function (result) { |
79
|
|
|
pico_nav.creatingWebsite(false); |
80
|
|
|
pico_result.createNewWebsiteResult(result); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
}, |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
deleteWebsite: function (id, name) { |
87
|
|
|
|
88
|
|
|
OC.dialogs.confirm( |
89
|
|
|
t('cms_pico', |
90
|
|
|
"This operation will delete the website {name} but its content will still be available in your files", |
91
|
|
|
{name: name}), |
92
|
|
|
t('cms_pico', 'Please confirm'), |
93
|
|
|
function (e) { |
94
|
|
|
if (e === true) { |
95
|
|
|
pico_nav.forceDeleteWebsite(id, name); |
96
|
|
|
} |
97
|
|
|
}); |
98
|
|
|
}, |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
forceDeleteWebsite: function (id, name) { |
102
|
|
|
$.ajax({ |
103
|
|
|
method: 'DELETE', |
104
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website'), |
105
|
|
|
data: { |
106
|
|
|
data: { |
107
|
|
|
id: id, |
108
|
|
|
name: name |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
}).done(function (result) { |
112
|
|
|
pico_result.deleteWebsiteResult(result); |
113
|
|
|
}); |
114
|
|
|
}, |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
creatingWebsite: function (creating) { |
118
|
|
|
|
119
|
|
|
pico_elements.cms_pico_new_submit.prop('disabled', creating); |
120
|
|
|
if (creating) { |
121
|
|
|
pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Please wait')); |
122
|
|
|
} else { |
123
|
|
|
pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Create a new website')); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
}, |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
updateWebsiteOption: function (site_id, key, value) { |
130
|
|
|
$.ajax({ |
131
|
|
|
method: 'POST', |
132
|
|
|
url: OC.generateUrl('/apps/cms_pico/personal/website/' + site_id + '/option/' + key), |
133
|
|
|
data: { |
134
|
|
|
value: value |
135
|
|
|
} |
136
|
|
|
}).done(function (res) { |
137
|
|
|
pico_result.displayWebsites(res.websites); |
138
|
|
|
}); |
139
|
|
|
}, |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
resetFields: function () { |
143
|
|
|
pico_elements.cms_pico_new_website.val(''); |
144
|
|
|
pico_elements.cms_pico_new_name.val(''); |
145
|
|
|
pico_elements.cms_pico_new_folder.val('/'); |
146
|
|
|
pico_elements.cms_pico_new_url.text(''); |
147
|
|
|
}, |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
generateTmplWebsite: function (entry) { |
151
|
|
|
var div = $('#tmpl_website'); |
152
|
|
|
if (!div.length) { |
153
|
|
|
return; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
var tmpl = div.html(); |
157
|
|
|
|
158
|
|
|
tmpl = tmpl.replace(/%%id%%/g, entry.id); |
159
|
|
|
tmpl = tmpl.replace(/%%name%%/g, escapeHTML(entry.name)); |
160
|
|
|
tmpl = tmpl.replace(/%%address%%/g, pico_define.nchost + pico_define.sites + |
161
|
|
|
escapeHTML(entry.site)); |
162
|
|
|
tmpl = tmpl.replace(/%%path%%/g, escapeHTML(entry.path)); |
163
|
|
|
|
164
|
|
|
if (entry.options.private === '1') { |
165
|
|
|
tmpl = tmpl.replace(/%%private%%/g, escapeHTML(entry.options.private)); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return tmpl; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
}; |